/*
 *    This file is part of CeluMap.
 *
 *    CeluMap is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    CeluMap is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    Copyright 2006, 2007, 2008 Gonzalo Merayo
 *    gonzalo (at) celumap.com.ar
 *    www.celumap.com.ar
 *
 */

package panel;
import image.GisImage;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import font.Font;
import geometry.Rectangle;
import screen.GisGraphics;

public class GraphicsProxy implements GisGraphics {

	Graphics g = null;
	int thick = 1;
	public GraphicsProxy(Graphics arg0) {
		g = arg0;
	}

	public void setColor(int color) {
		g.setColor(new Color(((color>>16)&0xFF), ((color>>8)&0xFF), (color&0xFF)));
	}

	public void setThickness(int thickness) {
		thick = thickness;
		
	}

	public void drawLine(int x1, int y1, int x2, int y2) {
		g.drawLine(x1, y1, x2, y2);
		if(thick >1){
			g.drawLine(x1+1,y1,x2+1,y2);
			g.drawLine(x1-1,y1,x2-1,y2);
			g.drawLine(x1,y1+1,x2,y2+1);
			g.drawLine(x1,y1-1,x2,y2-1);
    	}
	}

	public void point(int x, int y) {
		g.drawLine(x, y, x, y);
	}

	public void clear(Rectangle area) {
		g.drawRect(area.bbxi, area.bbyi, area.bbxf, area.bbyf);
	}

	static Font font = null;
	public void drawString(byte[] str, int x, int y, int dx, int dy) {
		if(font==null)
			font = new Font();
		setThickness(1);
		font.drawString(str, this, x, y, dx, dy);
		//g.setColor(Color.BLACK);
		//g.drawString(new String(str), x, y);
	}

	public void fill(int[] x, int[] y, int l) {
		g.fillPolygon(x, y, l);
	}

	public void image(GisImage im, int xi, int yi, int i) {
		BufferedImage b = new BufferedImage(im.getWidth(), im.getHeight(), BufferedImage.TYPE_INT_RGB);
		for(int y = 0;y < im.getHeight();y++){
			int oy = (y+im.getYInitOff())*im.getXoff();
			for(int x = 0;x < im.getWidth();x++){
				int c = im.getBuff()[im.getXInitOff()+x+oy];
				if(c != 0xFFFFFF)
					b.setRGB(x, y, c);
			}
		}
		g.drawImage(b, xi, yi, null, null);
	}

	public void setColor(byte color) {
		// TODO Auto-generated method stub
		
	}

}
